<template>
  <a-modal
    title="近一月小程序各页面浏览次数"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    class="modal_title"
    @cancel="close"
  >
    <a-spin :spinning="confirmLoading">
      <a-table
        ref="table"
        class="tdclass"
        size="middle"
        bordered
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无此图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt="图片不存在"
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无此文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="uploadFile(text)"
            >下载</a-button
          >
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">查看</a>
        </span>
      </a-table>
    </a-spin>
    <template slot="footer">
      <a-button type="default" @click="close">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
import { getAction } from '@/api/manage'
export default {
  name: 'ViewBrowerNumsModal',
  data() {
    return {
      width: 500,
      visible: false,
      model: {},
      confirmLoading: false,
      loading: false,
      columns: [
        {
          title: '页面',
          align: 'center',
          dataIndex: 'page_dictText',
        },
        {
          title: '浏览次数',
          align: 'center',
          dataIndex: 'browseNum',
        },
      ],
      dataSource:[]
    }
  },
  methods: {
    view(record) {
      let that = this
      that.confirmLoading = true
      getAction('/memberInfoDrawingBrowseNum/getByMemberId', { memberId: record.memberId })
        .then((res) => {
          if (res.success) {
            if (res.result.length > 0) {
              let total = {
                page_dictText: '合计',
                browseNum: 0,
              }
              res.result.forEach((rs) => {
                total.browseNum = total.browseNum + rs.browseNum
              })
              res.result.push(total)
            }
            that.dataSource = res.result
            return
          }
          that.$message.erroe(res.message)
        })
        .finally(() => {
          that.confirmLoading = false
        })
      that.visible = true
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    customRow(record, index) {
      return {
        style: {
          fontWeight: index == this.dataSource.length - 1 ? 'bold' : '400',
        },
      }
    },
  },
}
</script>
<style scoped>
/* @import '~@assets/less/modalForm.less'; */
.ant-modal-body .ant-spin-container {
  padding: 0;
}
</style>